home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWODMisc / Include / FWPoint.h < prev    next >
Encoding:
Text File  |  1996-08-16  |  15.3 KB  |  516 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPoint.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWPOINT_H
  11. #define FWPOINT_H
  12.  
  13. // ----- OpenDoc Includes -----
  14.  
  15. #ifndef FWODTYPS_H
  16. #include "FWODTyps.h"
  17. #endif
  18.  
  19. #ifndef FWFXMATH_H
  20. #include "FWFxMath.h"
  21. #endif
  22.  
  23. #ifndef SLPTRECT_H
  24. #include "SLPtRect.h"
  25. #endif
  26.  
  27. // ----- Foundation Includes -----
  28.  
  29. #ifndef FWSTDDEF_H
  30. #include "FWStdDef.h"
  31. #endif
  32.  
  33. #ifndef SOM_ODTransform_xh
  34. #include <Trnsform.xh>
  35. #endif
  36.  
  37. //========================================================================================
  38. //    Forward Declarations
  39. //========================================================================================
  40.  
  41. class ODTransform;
  42.  
  43. class FW_CPoint;
  44. class FW_CRect;
  45.  
  46. class FW_CWritableStream;
  47. class FW_CReadableStream;
  48.  
  49. //========================================================================================
  50. //    Global operators
  51. //========================================================================================
  52.  
  53. FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_SPoint& point);
  54. FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_SPoint& point);
  55.  
  56. FW_Boolean        operator==(const FW_SPoint& pt1, const FW_SPoint& pt2);
  57. FW_Boolean        operator!=(const FW_SPoint& pt1, const FW_SPoint& pt2);
  58. FW_Boolean        operator==(const FW_SPoint& pt1, const ODPoint& pt2);
  59. FW_Boolean        operator!=(const FW_SPoint& pt1, const ODPoint& pt2);
  60.  
  61. //========================================================================================
  62. //    Global
  63. //========================================================================================
  64.  
  65. extern const FW_CPoint        FW_kZeroPoint;
  66.  
  67. //========================================================================================
  68. //    Typedefs
  69. //========================================================================================
  70.  
  71. typedef unsigned short FW_XYSelector;
  72.  
  73. const FW_XYSelector FW_kHorizontal = 0;
  74. const FW_XYSelector FW_kVertical = 1;
  75.  
  76. //========================================================================================
  77. //    class FW_CPlatformPoint
  78. //========================================================================================
  79.  
  80. class FW_CPlatformPoint : public FW_SPlatformPoint
  81. {
  82. public:
  83.     FW_CPlatformPoint();
  84.     FW_CPlatformPoint(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy);
  85.     FW_CPlatformPoint(const FW_CPlatformPoint& plfmPoint);
  86.     FW_CPlatformPoint(const FW_SPlatformPoint& plfmPoint);
  87.     FW_CPlatformPoint(const FW_SPoint& point);
  88.         
  89.     FW_CPlatformPoint& operator=(const FW_CPlatformPoint& plfmPoint);
  90.     FW_CPlatformPoint& operator=(const FW_SPlatformPoint& plfmPoint);
  91.     FW_CPlatformPoint& operator=(const FW_SPoint& point);
  92.  
  93.     void Set(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy);
  94.     
  95.     FW_Boolean        operator==(const FW_CPlatformPoint& pt) const;
  96.     FW_Boolean        operator!=(const FW_CPlatformPoint& pt) const;
  97.  
  98.     FW_PlatformCoordinate X() const;
  99.     FW_PlatformCoordinate Y() const;
  100.  
  101.     FW_PlatformCoordinate& X();
  102.     FW_PlatformCoordinate& Y();
  103. };
  104.  
  105. //========================================================================================
  106. // Global utilities for working with FW_SPlatformPoint
  107. //========================================================================================
  108.  
  109. inline void FW_SetXY(FW_SPlatformPoint& pt, FW_PlatformCoordinate xx, FW_PlatformCoordinate yy)
  110. {
  111. #ifdef FW_BUILD_WIN
  112.     pt.x = xx; pt.y = yy;
  113. #endif
  114. #ifdef FW_BUILD_MAC
  115.     pt.h = xx; pt.v = yy;
  116. #endif
  117. }
  118.  
  119. inline FW_PlatformCoordinate& FW_PointX(FW_SPlatformPoint& pt)
  120. {
  121. #ifdef FW_BUILD_WIN
  122.     return pt.x;
  123. #endif
  124. #ifdef FW_BUILD_MAC
  125.     return pt.h;
  126. #endif
  127. }
  128.  
  129. inline FW_PlatformCoordinate& FW_PointY(FW_SPlatformPoint& pt)
  130. {
  131. #ifdef FW_BUILD_WIN
  132.     return pt.y;
  133. #endif
  134. #ifdef FW_BUILD_MAC
  135.     return pt.v;
  136. #endif
  137. }
  138.  
  139. inline FW_PlatformCoordinate FW_PointX(const FW_SPlatformPoint& pt)
  140. {
  141. #ifdef FW_BUILD_WIN
  142.     return pt.x;
  143. #endif
  144. #ifdef FW_BUILD_MAC
  145.     return pt.h;
  146. #endif
  147. }
  148.  
  149. inline FW_PlatformCoordinate FW_PointY(const FW_SPlatformPoint& pt)
  150. {
  151. #ifdef FW_BUILD_WIN
  152.     return pt.y;
  153. #endif
  154. #ifdef FW_BUILD_MAC
  155.     return pt.v;
  156. #endif
  157. }
  158.  
  159. //========================================================================================
  160. // Transformation utilities
  161. //========================================================================================
  162.  
  163. void            FW_Transform(Environment* ev, FW_SPoint& pt, ODTransform* transform);
  164. void            FW_InverseTransform(Environment* ev, FW_SPoint& pt, ODTransform* transform);
  165.  
  166. FW_CPoint        FW_TransformCopy(Environment* ev, const FW_SPoint& pt, ODTransform* transform);
  167. FW_CPoint        FW_InverseTransformCopy(Environment* ev, const FW_SPoint& pt, ODTransform* transform);
  168.  
  169. void             FW_TransformPoints(Environment* ev, ODTransform* transform, FW_SPoint* pts, long count);
  170. void             FW_InverseTransformPoints(Environment* ev, ODTransform* transform, FW_SPoint* pts, long count);
  171.  
  172. //========================================================================================
  173. // class FW_CPoint
  174. //========================================================================================
  175.  
  176. class FW_CPoint : public FW_SPoint
  177. {
  178. //----------------------------------------------------------------------------------------
  179. //    Constructors/Destructors
  180. //
  181. public:
  182.     FW_CPoint()
  183.         { x.fRep = 0; y.fRep = 0; }
  184.         
  185.     FW_CPoint(FW_Fixed xx, FW_Fixed yy)
  186.         { x = xx; y = yy; }
  187.  
  188.     FW_CPoint(FW_SPlatformPoint plfmPoint);
  189.     FW_CPoint(const FW_CPoint& point);
  190.     FW_CPoint(const FW_SPoint& point);
  191.     FW_CPoint(const ODPoint& odPoint);
  192.  
  193.     FW_CPoint(FW_CReadableStream& stream);
  194.  
  195. //----------------------------------------------------------------------------------------
  196. //    operators
  197. //
  198. public:
  199.     // ----- Assignement -----    
  200.     FW_CPoint&         operator=(const FW_SPoint& point);
  201.     FW_CPoint&         operator=(const FW_CPoint& point);
  202.     FW_CPoint&         operator=(const ODPoint& odPoint);
  203.     FW_CPoint&         operator=(FW_SPlatformPoint plfmPoint);
  204.  
  205.     // ----- Conversion -----
  206.  
  207. //     It is too dangerous to have automatic conversion. Use AsPlatformPoint.
  208. //    operator FW_SPlatformPoint() const;
  209.  
  210.     operator        ODPoint() const
  211.         { return * (ODPoint*) this; }
  212.  
  213.     operator        ODPoint*()
  214.         { return (ODPoint*) this; }
  215.  
  216.     operator        FW_SPoint*() const
  217.         { return (FW_SPoint*) this; }
  218.  
  219.     // ----- Modification -----    
  220.     FW_CPoint&        operator+=(const FW_SPoint& point);
  221.     FW_CPoint&        operator-=(const FW_SPoint& point);
  222.     FW_CPoint&        operator+=(const ODPoint& odPoint);
  223.     FW_CPoint&        operator-=(const ODPoint& odPoint);
  224.     
  225.     FW_CPoint        operator+(const FW_SPoint& point) const;
  226.     FW_CPoint        operator-(const FW_SPoint& point) const;
  227.     FW_CPoint        operator+(const ODPoint& odPoint) const;
  228.     FW_CPoint        operator-(const ODPoint& odPoint) const;
  229.     FW_CPoint        operator-()  const;
  230.     
  231.     FW_CPoint&        operator+=(FW_CPlatformPoint plfmPoint);
  232.     FW_CPoint&        operator-=(FW_CPlatformPoint plfmPoint);
  233.     FW_CPoint        operator+(FW_CPlatformPoint plfmPoint) const;
  234.     FW_CPoint        operator-(FW_CPlatformPoint plfmPoint) const;
  235.  
  236.     FW_Fixed&         operator[](FW_XYSelector selector);
  237.     FW_Fixed         operator[](FW_XYSelector selector) const;
  238.     
  239. //----------------------------------------------------------------------------------------
  240. //    New API
  241. //
  242. public:
  243.     // ----- Modification -----    
  244.     void             Clear();
  245.     void             Set(FW_Fixed xx, FW_Fixed yy);
  246.     void            Offset(FW_Fixed xx, FW_Fixed yy);
  247.     void            Map(const FW_SRect& srcRect, const FW_SRect& destRect);
  248.  
  249.     // ----- Conversion -----
  250.     FW_CPlatformPoint    AsPlatformPoint() const;
  251.  
  252.     // ----- Accessors -----
  253.     short            IntX() const;
  254.     short            IntY() const;
  255.     
  256.     // ----- OpenDoc transforms -----
  257.  
  258.         // Modify the point
  259.     void            Transform(Environment* ev, ODTransform* transform)
  260.         { FW_Transform(ev, *this, transform); }
  261.     
  262.     void            InverseTransform(Environment* ev, ODTransform* transform)
  263.         { FW_InverseTransform(ev, *this, transform); }
  264.  
  265.         // Return a transformed copy
  266.     FW_CPoint        TransformCopy(Environment* ev, ODTransform* transform) const
  267.         { return FW_TransformCopy(ev, *this, transform); }
  268.         
  269.     FW_CPoint        InverseTransformCopy(Environment* ev, ODTransform* transform) const
  270.         { return FW_InverseTransformCopy(ev, *this, transform); }
  271.  
  272.     // ----- Utilities -----
  273.     static FW_XYSelector GetOrthogonal(FW_XYSelector selector)
  274.                                 {return (selector + 1) & 1;}    
  275. };
  276.  
  277. //========================================================================================
  278. //    inlines
  279. //========================================================================================
  280.  
  281. //----------------------------------------------------------------------------------------
  282. //    FW_CPoint::Clear
  283. //----------------------------------------------------------------------------------------
  284.  
  285. inline void FW_CPoint::Clear()
  286. {
  287.     x.fRep = y.fRep = 0;
  288. }
  289.  
  290. //----------------------------------------------------------------------------------------
  291. //    FW_CPoint::Set
  292. //----------------------------------------------------------------------------------------
  293. inline void FW_CPoint::Set(FW_Fixed xx, FW_Fixed yy)
  294. {
  295.     x = xx, y = yy;
  296. }
  297.  
  298. //----------------------------------------------------------------------------------------
  299. //    FW_CPoint::IntX
  300. //----------------------------------------------------------------------------------------
  301. inline short FW_CPoint::IntX() const
  302. {
  303.     return FW_FixedToInt(x);
  304. }
  305.  
  306. //----------------------------------------------------------------------------------------
  307. //    FW_CPoint::IntY
  308. //----------------------------------------------------------------------------------------
  309. inline short FW_CPoint::IntY() const
  310. {
  311.     return FW_FixedToInt(y);
  312. }
  313.  
  314. //----------------------------------------------------------------------------------------
  315. //    FW_CPlatformPoint::FW_CPlatformPoint
  316. //----------------------------------------------------------------------------------------
  317. inline FW_CPlatformPoint::FW_CPlatformPoint()
  318. {
  319. #ifdef FW_BUILD_WIN
  320.     x = y = 0;
  321. #endif
  322. #ifdef FW_BUILD_MAC
  323.     h = v = 0;
  324. #endif
  325. }
  326.  
  327. //----------------------------------------------------------------------------------------
  328. //    FW_CPlatformPoint::FW_CPlatformPoint
  329. //----------------------------------------------------------------------------------------
  330. inline FW_CPlatformPoint::FW_CPlatformPoint(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy)
  331. {
  332. #ifdef FW_BUILD_WIN
  333.     x = xx; y = yy;
  334. #endif
  335. #ifdef FW_BUILD_MAC
  336.     h = xx; v = yy; 
  337. #endif
  338. }
  339.  
  340. //----------------------------------------------------------------------------------------
  341. //    FW_CPlatformPoint::FW_CPlatformPoint
  342. //----------------------------------------------------------------------------------------
  343. inline FW_CPlatformPoint::FW_CPlatformPoint(const FW_SPoint& point)
  344. {
  345. #ifdef FW_BUILD_WIN
  346.     x = FW_FixedToInt(point.x), y = FW_FixedToInt(point.y);
  347. #endif
  348. #ifdef FW_BUILD_MAC
  349.     h = FW_FixedToInt(point.x), v = FW_FixedToInt(point.y);
  350. #endif
  351. }
  352.  
  353. //----------------------------------------------------------------------------------------
  354. //    FW_CPlatformPoint::FW_CPlatformPoint
  355. //----------------------------------------------------------------------------------------
  356. inline FW_CPlatformPoint::FW_CPlatformPoint(const FW_CPlatformPoint& plfmPoint)
  357. {
  358. #ifdef FW_BUILD_WIN
  359.     x = plfmPoint.x; y = plfmPoint.y;
  360. #endif
  361. #ifdef FW_BUILD_MAC
  362.     h = plfmPoint.h; v = plfmPoint.v;
  363. #endif
  364. }
  365.  
  366. //----------------------------------------------------------------------------------------
  367. //    FW_CPlatformPoint::FW_CPlatformPoint
  368. //----------------------------------------------------------------------------------------
  369. inline FW_CPlatformPoint::FW_CPlatformPoint(const FW_SPlatformPoint& plfmPoint)
  370. {
  371. #ifdef FW_BUILD_WIN
  372.     x = plfmPoint.x; y = plfmPoint.y;
  373. #endif
  374. #ifdef FW_BUILD_MAC
  375.     h = plfmPoint.h; v = plfmPoint.v;
  376. #endif
  377. }
  378.  
  379. //----------------------------------------------------------------------------------------
  380. //    FW_CPlatformPoint::operator=
  381. //----------------------------------------------------------------------------------------
  382. inline FW_CPlatformPoint& FW_CPlatformPoint::operator=(const FW_SPoint& point)
  383. {
  384. #ifdef FW_BUILD_WIN
  385.     x = FW_FixedToInt(point.x), y = FW_FixedToInt(point.y);
  386. #endif
  387. #ifdef FW_BUILD_MAC
  388.     h = FW_FixedToInt(point.x), v = FW_FixedToInt(point.y);
  389. #endif
  390.     return *this;
  391. }
  392.  
  393. //----------------------------------------------------------------------------------------
  394. //    FW_CPlatformPoint::operator=
  395. //----------------------------------------------------------------------------------------
  396. inline FW_CPlatformPoint& FW_CPlatformPoint::operator=(const FW_CPlatformPoint& plfmPoint)
  397. {
  398. #ifdef FW_BUILD_WIN
  399.     x = plfmPoint.x; y = plfmPoint.y;
  400. #endif
  401. #ifdef FW_BUILD_MAC
  402.     h = plfmPoint.h; v = plfmPoint.v; 
  403. #endif
  404.     return *this;
  405. }
  406.  
  407. //----------------------------------------------------------------------------------------
  408. //    FW_CPlatformPoint::operator=
  409. //----------------------------------------------------------------------------------------
  410. inline FW_CPlatformPoint& FW_CPlatformPoint::operator=(const FW_SPlatformPoint& plfmPoint)
  411. {
  412. #ifdef FW_BUILD_WIN
  413.     x = plfmPoint.x; y = plfmPoint.y;
  414. #endif
  415. #ifdef FW_BUILD_MAC
  416.     h = plfmPoint.h; v = plfmPoint.v; 
  417. #endif
  418.     return *this;
  419. }
  420.  
  421. //----------------------------------------------------------------------------------------
  422. //    FW_CPlatformPoint::Set
  423. //----------------------------------------------------------------------------------------
  424. inline void FW_CPlatformPoint::Set(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy)
  425. {
  426. #ifdef FW_BUILD_WIN
  427.     x = xx; y = yy;
  428. #endif
  429. #ifdef FW_BUILD_MAC
  430.     h = xx; v = yy;
  431. #endif
  432. }
  433.  
  434. //----------------------------------------------------------------------------------------
  435. //    FW_CPlatformPoint::X
  436. //----------------------------------------------------------------------------------------
  437. inline FW_PlatformCoordinate FW_CPlatformPoint::X() const
  438. {
  439. #ifdef FW_BUILD_WIN
  440.     return x;
  441. #endif
  442. #ifdef FW_BUILD_MAC
  443.     return h;
  444. #endif
  445. }
  446.  
  447. //----------------------------------------------------------------------------------------
  448. //    FW_CPlatformPoint::Y
  449. //----------------------------------------------------------------------------------------
  450. inline FW_PlatformCoordinate FW_CPlatformPoint::Y() const
  451. {
  452. #ifdef FW_BUILD_WIN
  453.     return y;
  454. #endif
  455. #ifdef FW_BUILD_MAC
  456.     return v;
  457. #endif
  458. }
  459.  
  460. //----------------------------------------------------------------------------------------
  461. //    FW_CPlatformPoint::X
  462. //----------------------------------------------------------------------------------------
  463. inline FW_PlatformCoordinate& FW_CPlatformPoint::X()
  464. {
  465. #ifdef FW_BUILD_WIN
  466.     return x;
  467. #endif
  468. #ifdef FW_BUILD_MAC
  469.     return h;
  470. #endif
  471. }
  472.  
  473. //----------------------------------------------------------------------------------------
  474. //    FW_CPlatformPoint::Y
  475. //----------------------------------------------------------------------------------------
  476.  
  477. inline FW_PlatformCoordinate& FW_CPlatformPoint::Y()
  478. {
  479. #ifdef FW_BUILD_WIN
  480.     return y;
  481. #endif
  482. #ifdef FW_BUILD_MAC
  483.     return v;
  484. #endif
  485. }
  486.  
  487. //----------------------------------------------------------------------------------------
  488. //    FW_CPlatformPoint::operator==
  489. //----------------------------------------------------------------------------------------
  490.  
  491. inline FW_Boolean FW_CPlatformPoint::operator==(const FW_CPlatformPoint& pt) const
  492. {
  493. #ifdef FW_BUILD_WIN
  494.     return x == pt.x && y == pt.y;
  495. #endif
  496. #ifdef FW_BUILD_MAC
  497.     return h == pt.h && v == pt.v;
  498. #endif
  499. }
  500.  
  501. //----------------------------------------------------------------------------------------
  502. //    FW_CPlatformPoint::operator!=
  503. //----------------------------------------------------------------------------------------
  504.  
  505. inline FW_Boolean FW_CPlatformPoint::operator!=(const FW_CPlatformPoint& pt) const
  506. {
  507. #ifdef FW_BUILD_WIN
  508.     return x != pt.x || y != pt.y;
  509. #endif
  510. #ifdef FW_BUILD_MAC
  511.     return h != pt.h || v != pt.v;
  512. #endif
  513. }
  514.  
  515. #endif
  516.